package com.sicau.controller;

import com.sicau.entity.User;
import com.sicau.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
	@Autowired
	private LoginService loginService;
	@RequestMapping("/login")
	public String login(String account,String password) {
		System.out.println(account);
		String result = loginService.login(account,password);
		System.out.println(result);
		return result;
	}
	@RequestMapping("/insert")
	public String insert(int uid,String account,String password,int lid,int stuclass) {
		User user = new User();
		user.setUid(uid);
		user.setAccount(account);
		user.setPassword(password);
		user.setLid(lid);
		user.setStuclass(stuclass);
		int result = loginService.insert(user);
		if(result == 0){
			return "error";
		}
		return "welcome";
	}
	@RequestMapping("/select")
	public ModelAndView select(int uid) {
		User user = loginService.select(uid);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("user",user);
		modelAndView.setViewName("welcome");
		return modelAndView;
	}
}
